<!DOCTYPE html>
<html>

<head>
	<title>登录</title>
	<link rel="stylesheet" href="/static/css/amazeui.min.css">
	<link rel="stylesheet" href="/static/css/app.css">
</head>

<body class="theme-white">
	<div id="login">
		<!--内容区域 
    <div class="head">
        <div class="head" style="margin-top: 200px">
            <h1>养悦源后台管理系统</h1>
        </div>

        <div class="row-content"></div>
    </div>-->


		<!-- 弹出框 -->
		<!--<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
			<div class="am-modal-dialog">
				<div class="am-modal-hd">提示</div>
				<div class="am-modal-bd" id='alert_bd'>
					Hello world！
				</div>
				<div class="am-modal-footer">
					<span class="am-modal-btn">确定</span>
				</div>
			</div>
		</div>-->



		<div class="tpl-login">
			<div class="tpl-login-content">
				<!--<div class="tpl-login-logo">
				
                </div>-->
				<div class="tpl-login-title">
					<strong>养悦源后台管理系统</strong>
				</div>


				<form class="am-form tpl-form-line-form" action="" data-am-validator>
					<div class="am-form-group">
						<!--<label for="doc-ipt-3" class="am-u-sm-2 am-form-label">账户</label>-->
						<div class="rightBox">
							<input type="text" id="username" name="username" placeholder="输入账号" />
						</div>
					</div>

					<div class="am-form-group">
						<!--<label for="doc-ipt-pwd-2" class="am-u-sm-2 am-form-label">密码</label>-->
						<div class="rightBox">
							<input type="password" id="password" name="password" placeholder="输入密码" />
						</div>
					</div>
	<div class="am-form-group">
						<!--<label for="doc-ipt-pwd-2" class="am-u-sm-2 am-form-label">验证码</label>-->
						<div class="rightBox am-cf">
							<input class="am-u-sm-5 am-fl" type="text" name="captcha" id="captcha" placeholder="输入验证码" style="width: 60%;" />
							<div id="img" class="am-fr" style=""></div>
						</div>
					</div>
					<div class="am-form-group yz">
						<!--<label for="doc-ipt-pwd-2" class="am-u-sm-2 am-form-label">验证码</label>-->
						<div class="rightBox am-cf">							
							<span class="am-badge am-badge-danger"></span>
						</div>
					</div>

					<div class="am-form-group">
						<div class="rightBox ">
							<button type="submit" id="form" class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn">登录</button>
						</div>
					</div>
					<div class="am-form-group">
						<div class="rightBox am-fr sub-btn">
<!--							<a href="javascript:;"  class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success tpl-login-btn">忘记密码</a>-->
<!--							<a class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success tpl-login-btn">合作协议></a>-->
						</div>
					</div>
				</form>
			
			</div>
		</div>
	</div>

	<script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/appkit.js"></script>
	<script>
	
		// 验证码
		function getCaptcha() {
			$.get("/admin/account/captcha", function (htmlStr) {
				console.log(htmlStr);
				img = '<img id="Imageid" src="/static/captcha/' + htmlStr + '">';
				$("#img").html($(img));

			})
		}
		getCaptcha();

		// 登录
		$('form').submit(function () {
			var username = $('#username').val();
			var password = $('#password').val();
			var captcha = $('#captcha').val();


			if (username == "" || password == "" || captcha == "") {
			    alert('账号，密码，验证码不能为空！')
				return false;
			}

			$.get("/admin/account/token?username=" + username + "&password=" + password + "&captcha=" + captcha, function (json) {
			    console.log(json);
				if (json.errcode == 0) {



				    // android
                    if(typeof(window.insertObj) != 'undefined') {
                        window.insertObj.WebJs_login_click(json.errmsg);
                    }
                    // iOS 
                    if(typeof(window.webkit) != "undefined"){ // .messageHandlers.WebJs_login_click.postMessage
                        window.webkit.messageHandlers.WebJs_login_click.postMessage(json.errmsg);
                    }

					//  跳转到管理首页
					window.location.href = "<?php echo $base_url;?>admin/users/lists";
				}  else {
                    alert(json.errmsg);
					getCaptcha();					
					return false;
				}

			}, 'json');

			return false;
		})



		//刷新验证码
		$('#img').click(function () {
			getCaptcha();
		});

	</script>


</body>

</html>
